package org.example.myleet.p860;

public class Solution {
    public boolean lemonadeChange(int[] bills) {
        if (bills.length == 0) {
            return true;
        }
        if (bills[0] > 5) {
            return false;
        }
        //0-5,1-10
        int[] count = new int[2];
        for (int bill : bills) {
            if (bill == 5) {
                ++count[0];
            } else if (bill == 10) {
                if (count[0] < 1) {
                    return false;
                }
                --count[0];
                ++count[1];
            } else {
                if (count[0] > 0 && count[1] > 0) {
                    --count[0];
                    --count[1];
                } else if (count[0] > 2) {
                    count[0] = count[0] - 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
